/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.controller;

import com.thienloc.omap.entity.RequestQueue;
import com.thienloc.omap.session.RequestQueueFacade;
import com.thienloc.omap.util.JsfUtil;
import java.math.BigInteger;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author GiangLT
 */
@ManagedBean
@ViewScoped
public class RequestQueueFiller {

    private Integer numOfBroadcasts;
    private Integer speed;
    @EJB
    private RequestQueueFacade requestQueueFacade;

    public void createRequest() {
        int cnt = 0;
        for (int i = 0; i < numOfBroadcasts; i++) {

            
            RequestQueue requestQueue = new RequestQueue();
            requestQueue.setCallBack("smsgate_viettel6771");
            requestQueue.setCpNumber("6771");
            requestQueue.setDeliverProvider("smsgate_viettel6771");
            requestQueue.setLastCheckTime(new Date());
            requestQueue.setMsisdn(null);
            requestQueue.setSelectTime(new Date());
            requestQueue.setReceivedTime(new Date());
            requestQueue.setRequestDetail(null);
            requestQueue.setOldContent(null);


            requestQueue.setStatus(null);
            try {
                requestQueueFacade.create(requestQueue);
            } catch (Exception ex) {
                Logger.getLogger(RequestQueueFiller.class.getName()).log(Level.SEVERE, null, ex);
            }

            cnt++;
            if (cnt >= speed) {
                cnt = 0;
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(RequestQueueFiller.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        
        JsfUtil.addSuccessMessage("Done", "Done broadcasting");
    }

    public Integer getNumOfBroadcasts() {
        return numOfBroadcasts;
    }

    public void setNumOfBroadcasts(Integer numOfBroadcasts) {
        this.numOfBroadcasts = numOfBroadcasts;
    }

    public Integer getSpeed() {
        return speed;
    }

    public void setSpeed(Integer speed) {
        this.speed = speed;
    }
}
